<template>
	<view>
			<!-- <view v-if="showAd" style="width: 250px; height: 250px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9999;">
				<u-icon @click="closeAd" name="close" style="position: absolute; top:4%;right: 4%; z-index: 99999;"></u-icon>
				<u-image :src="imgSrc" width="250px" height="250px" showMenuByLongpress="true" @click="toDetail"></u-image>
			</view> -->
			<!-- 广告 -->
		<view class="page">
			<!-- 空闲教室头部 ——start -->
			<view class="head">
				<!-- 搜索 ——start -->
				<!-- 查询弹出框 ——start-->
				<search-pop-up @toSearch="toSearch"></search-pop-up>
				<!-- 查询弹出框 ——start-->
				<!-- 搜索 ——end -->
				<!-- 空闲教室表格头部 ——start-->
				<view class="table_head">
					<view>教室</view>
					<view>上午</view>
					<view>下午</view>
					<view>晚上</view>
				</view>
				<!-- 空闲教室表格头部 ——end-->
			</view>
			<!-- 空闲教室头部 ——end -->
			<!-- 空闲教室表格body ——start -->
			<view class="table_body" v-if="haveData">
				<view class="body_row" v-for="(item,index) in classRoom" :key="index">
					<view class="row_left" @click="haveDetail(item.name)">{{item.name}}</view>
					<view class="row_right">
						<view class="cell" v-for="(item1,index1) in section " :key="index1">
							<!-- 无课状态 ——start -->
							<view class="iconfont icon-v16kecheng-wuke-copy" style="color:#D6D6D6;font-size: 38rpx;"
								v-if="item.section.indexOf(index1 + 1) != -1"></view>
							<!-- 无课状态 ——end -->
							<!-- 有课状态 ——start -->
							<view class="iconfont icon-v16kecheng-wuke-copy" style="color:#23b8ff;font-size: 38rpx;"
								v-else>
							</view>
							<!-- 有课状态 ——end -->
						</view>
					</view>
				</view>
			</view>
			<view v-if="!haveData" class="tip">
				<view class="iconfont icon-a-weixiaokaixingaoxing-13"
					style="color:#6B6B6B;margin-right: 25rpx;font-size: 78rpx;"></view>
				<view style="font-size: 56rpx;">寒假快乐!</view>
			</view>
			<!-- 空闲教室表格body ——end -->
			<!-- 提示框 ——start -->
			<u-modal v-model="showDetail" width="60%" title="当前教室" :content="content"></u-modal>
			<!-- 提示框 ——end -->
		</view>
	</view>

</template>

<script>
	import searchPopUp from "../components/searchPopUp/searchPopUp.vue"
	export default {
		onLoad() {
			// if (Math.floor((Math.random()*100)+1)%3 === 0) {
			//                 this.showAd = false
			//         }
			// uni.getStorage({
			// 	key: 'imgSrc',
			// 	success: (res) => {
			// 		console.log(1)
			// 		const arr = JSON.parse(res.data);
			// 		this.imgSrcArr = arr
			// 		this.imgSrc = this.imgSrcArr[0]
			// 		const img = this.imgSrcArr.shift()
			// 		this.imgSrcArr.push(img)
			// 		uni.setStorage({
			// 			key: 'imgSrc',
			// 			data: JSON.stringify(this.imgSrcArr),
			// 			success: function () {
			// 				console.log('success');
			// 			}
			// 		});
			// 	},
			// 	fail: () => {
			// 		console.log(3)
			// 		this.imgSrc = this.imgSrcArr[0]
			// 		const img = this.imgSrcArr.shift()
			// 		this.imgSrcArr.push(img)
			// 		uni.setStorage({
			// 			key: 'imgSrc',
			// 			data: JSON.stringify(this.imgSrcArr),
			// 			success: function () {
			// 				console.log('success');
			// 			}
			// 		});
			// 	}
			// });
			},
		async created() {
			//获取设备信息
			let that = this;
			//初始数值
			let initData = new Object();
			console.log(getApp().globalData.isHaiZhu)
			if (getApp().globalData.isHaiZhu) {
				initData.campus = '海珠校区';
				initData.building = '教学楼';
			} else {
				initData.campus = '白云校区';
				initData.building = '曾宪梓楼';
			}

			let res = await getApp().UniRequest("/week", "Get", "", ""); //获得当前周
			console.log(res)
			initData.week = res.data.week;
			let xingqi = "日一二三四五六".charAt(new Date().getDay()); //获得当前周几
			let xingqiArray = ["一", "二", "三", "四", "五", "六", "日"];
			initData.xingqi = xingqiArray.indexOf(xingqi) + 1;
			this.getResult(initData)
		},
		data() {
			return {
				info: null,
				section: ['', '', '', '', '', '', '', '', '', '', '', ''],
				classRoom: [],
				content: '',
				showDetail: false,
				haveData: false,
				// showAd:true,
				// imgSrc: 'http://1.14.247.152:9797/images/haqgg.jpg',
				// imgAdSrcArr: 'https://broccoli.uc.cn/apps/AiPHSRQI1/routes/l8xSojNOb?uc_param_str=dsdnfrpfbivesscpgimibtbmnijblauputogpintnwktprchmt&entry=fbyaoqingmabmcs-h5&code=119006&nickname=%E5%90%83%E8%B4%A7%E7%AC%94%E8%AE%B0%E5%AE%A3%E4%BC%A0%E5%A4%A7%E4%BD%BF&avator=http%3A%2F%2Fpeco-img.uc.cn%2Fimage%2Ffood_community%2Funk%2Fugc%2FE1NzM3OTMwMTAwMT%2F616a82dca13dbd05304c73ed64316b80%3Fuid%3Dfood_community%26ts%3D1646671185575%26sign%3D14b64f8783af3cb89c2b0b20d95f5f33&user_id=NSCSnMA2o2Stvog09Ed2oxMZ',
				windowHeight: 0 //屏幕高度

			}
		},
		// computed: {
		// 	position() {
		// 		let height = this.windowHeight + 'px';
		// 		return 'margin-top: calc( @{height} - 180rpx)';
		// 	}
		// },
		methods: {
			// toDetail(index){
			// 	uni.navigateTo({
			// 		url: '/page_webview/webview?url=' + encodeURIComponent(this.imgAdSrcArr)
			// 	});
			// },
			// closeAd() {
			// 	this.showAd=false;
			// },
			
			// previewImg() {
			//                 let _this = this;
			//                 let imgsArray = [];
			//                 imgsArray[0] = this.imgSrc
			//                 uni.previewImage({
			//                     current: 0,
			//                     urls: imgsArray
			//                 });
			// },
			
			search() {
				// console.log('执行')
			},
			haveDetail(e) {
				this.showDetail = true;
				this.content = e;
			},
			toSearch(e) {
				// console.log('结果',e);
				this.getResult(e)
			},
			//获得查询结果
			async getResult(data) {
				uni.showLoading({
					title: '加载中..',
					mask: true
				});
				console.log('空闲教室参数', data)
				let header = new Object()
				header.Authority = uni.getStorageSync("Authority")
				let res = await getApp().UniRequest("/freeRoom/getFreeByFour", "Get", data, header)
				console.log('结果', res)
				res.forEach((item, index) => {
					let start = item.name.indexOf('楼');
					let temp = item.name.slice(start + 1, item.name.length);
					if (temp.indexOf(')') != -1) { //去除（白）
						temp = temp.slice(temp.indexOf(')') + 1, temp.length)
					}
					item.name = temp;
				})
				this.classRoom = res;
				if (this.classRoom.length == 0) {
					this.haveData = false
				} else {
					this.haveData = true
				}
				uni.hideLoading();
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});

			}
		},
		components: {
			searchPopUp
		}

	}
</script>

<style lang="less">
	.page {
		width: 100%;
		position: relative;
		// /deep/ .u-image {
			
		// 	// border-radius: 35px !important;
			
		// 	.u-image__image {
		// 		border-radius: 25px !important;
		// 	}
		// }
		
		.head {
			position: fixed;
			top: 0;
			width: 100%;

			.search {
				height: 70rpx;
				font-size: 38rpx;
				background-color: #FFFFFF;

				.search_box {
					display: flex;
					width: 220rpx;
					text-align: center;
					height: 100%;
					margin: 0 auto;
					color: #23b8ff;
					// background-color: #007AFF;
				}
			}

			.table_head {
				display: flex;
				height: 70rpx;
				background-color: #23b8ff;

				view {
					width: 25%;
					text-align: center;
					font-size: 38rpx;
					color: #FFFFFF;
					line-height: 70rpx;
				}
			}
		}

		.table_body {
			width: 100%;
			margin-top: 430rpx;

			.body_row {
				display: flex;
				width: 100%;
				height: 70rpx;
				line-height: 60rpx;
				border-bottom: 1rpx solid #23b8ff;

				.row_left {
					width: 25%;
					text-align: center;
					font-size: 32rpx;
					color: #23b8ff;
					border-right: 1rpx solid #23b8ff;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.row_right {
					display: flex;
					width: 100%;
					text-align: center;

					.cell {
						width: 7.69%;

					}

					&>.cell:nth-child(5),
					&>.cell:nth-child(9) {
						border-right: 1rpx solid #23b8ff;
					}

					&>.cell:nth-child(10) {
						margin-left: 20rpx;
					}

				}
			}

		}

		.tip {
			width: 480rpx;
			position: absolute;
			top: 620rpx; //后面看能不能用变量
			left: 50%;
			margin-left: -190rpx;
			display: flex;
			letter-spacing: 2rpx;
			font-size: 42rpx;
		}
	}
</style>
